package com.jdz.gxq.info.admin.employmentneed.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.jdz.gxq.info.admin.employmentneed.bo.Employmentneed;
import com.jdz.gxq.info.admin.employmentneed.form.EmploymentneedListForm;
import com.jdz.gxq.info.admin.employmentneed.service.EmploymentneedService;
import com.jdz.gxq.info.common.action.CommonAction;
import com.jdz.gxq.info.common.bo.PageBean;

public class EmploymentneedListAction extends CommonAction {

	private EmploymentneedService employmentneedService = null;
	 
	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {
		
		EmploymentneedListForm employmentneedListForm = (EmploymentneedListForm) form;
		
		String needTime = employmentneedListForm.getNeedTime();

		int totalCount = employmentneedService.getEmploymentneedsCount(needTime);
		
		int currentPage = employmentneedListForm.getPageIndex();

		PageBean pageBean = new PageBean(totalCount, currentPage);
		
		employmentneedListForm.setPageIndex(pageBean.getCurrentPage());
		
		Map<String, Object> params = new HashMap<String, Object>();
		
		// 分页用
		params.put("startRow", pageBean.getPageStartRow() - 1);
		params.put("rowSize", pageBean.getPageSize());
		params.put("needTime", needTime);
		
		List<Employmentneed> employmentneedList = employmentneedService.getEmploymentneeds(params);
		
		request.setAttribute("employmentneedList", employmentneedList);
		request.setAttribute("pageBean", pageBean);
		
		return mapping.findForward("success");
	}

	public void setEmploymentneedService(EmploymentneedService employmentneedService) {
		this.employmentneedService = employmentneedService;
	}
}

